{extend name="iframe" /}

{block name="body"}
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
    <form action="{:request()->url()}" method="post" class="xn_ajax" data-type="open">
        <div class="layui-form-item">
            <label class="layui-form-label">位置</label>
            <div class="layui-input-inline">
                <select name="position1" lay-filter="position1">
                    <option value="0">请选择</option>
                    {foreach name="position1List" item="vo"}
                    <option value="{$vo.id}" {if $data.position1==$vo.id}selected{/if}>{$vo.title}</option>
                    {/foreach}
                </select>
            </div>
            <div class="layui-input-inline {if $data.position1!=3}layui-hide{/if}" id="pos2">
                <select name="position2" id="position2">
                    <option value="0">请选择</option>
                    {foreach name="position2List" item="vo"}
                    <option value="{$vo.id}" {if $data.position2==$vo.id}selected{/if}>{$vo.sort}.{$vo.title}</option>
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">内容</label>
            <div class="layui-input-block">
                <textarea name="title" class="layui-textarea">{$data.title}</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" lay-submit class="layui-btn">保存</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
{/block}

{block name="js"}
<script>
    var form = layui.form;
    form.on('select(position1)', function(res) { 
        $("#position2").empty();
        if(res.value==3){
            $.get("{:url('admin/DataContentChipPosition/getSonPosition')}?pid="+res.value,function(result){
                if(result.status){
                    $("#position2").append(new Option('请选择',0));
                    $.each(result.data,function(index,item){
                        $("#position2").append(new Option(item.sort+'.'+item.title,item.id));
                    });
                    form.render("select");
                }
            });
            $('#pos2').removeClass('layui-hide');
        }else{
            $("#position2").append(new Option('请选择',0));
            form.render("select");
            $('#pos2').addClass('layui-hide');
        }
    })
</script>
{/block}

